package apt.action;

import java.util.Map;

import apt.dao.UserDao;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginUserAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String userName;
	private String password;
	private Map<String, Object> session;
	private UserDao userDao;

	public LoginUserAction() {
		userDao = new UserDao();
	}

	public String executeLogin() {
		try {
			int status = userDao.getUserLogin(userName, password);
			session = ActionContext.getContext().getSession();
			if (status > 0) {
				System.out.println("run");
				
				session.put("object", "user");
				session.put("username", userName);
				System.out.println("end");
				System.out.println("login : " + session.get("object"));
				System.out.println("User Name : " + session.get("string"));
				System.out.println("pass : " + password);
				System.out.println("size of map=" + session.size());
				// ActionContext.getContext().getSession().putAll(map);

				//ActionContext.getContext().getSession().put("login", map);
				// ActionContext.getContext().getSession().put("userName",userName);
			} else {
				return ERROR;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String executeLogout() {
		session = ActionContext.getContext().getSession();
		session.remove("object");
		session.remove("username");
		
		return SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	
}
